package controller

import (
	"gin-epg/internal/app/common/rsp"
	"gin-epg/internal/app/service"
	"github.com/gin-gonic/gin"
	"log"
)

func InitChannel(c *gin.Context) {
	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Cron job failed: %v", r)
			}
		}()

		if err := service.InitChannel(); err != nil {
			log.Printf("Cron job failed: %v", err)
		} else {
			log.Println("Cron job completed successfully")
		}
	}()
	// 返回响应
	rsp.Success(c, "请求成功", nil)
}
func InitLogo(c *gin.Context) {
	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Cron job failed: %v", r)
			}
		}()

		if err := service.InitLogo(); err != nil {
			log.Printf("Cron job failed: %v", err)
		} else {
			log.Println("Cron job completed successfully")
		}
	}()
	// 返回响应
	rsp.Success(c, "请求成功", nil)
}

func InitGroup(c *gin.Context) {
	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Cron job failed: %v", r)
			}
		}()

		if err := service.InitGroup(); err != nil {
			log.Printf("Cron job failed: %v", err)
		} else {
			log.Println("Cron job completed successfully")
		}
	}()
	// 返回响应
	rsp.Success(c, "请求成功", nil)
}

func InitAlias(c *gin.Context) {
	go func() {
		defer func() {
			if r := recover(); r != nil {
				log.Printf("Cron job failed: %v", r)
			}
		}()

		if err := service.InitAlias(); err != nil {
			log.Printf("Cron job failed: %v", err)
		} else {
			log.Println("Cron job completed successfully")
		}
	}()
	// 返回响应
	rsp.Success(c, "请求成功", nil)
}
